'''
Created on 2011-6-11

@author: JHL
'''
from django import newforms as forms
from t8.user.models import userModel as user
import time

class registerForm(forms.Form):
    name = forms.CharField(max_length=30)
    password = forms.CharField(max_length=32)
    
    def save(self):
        user.name=self.name
        user.password= self.password
        user.createtime = time.time()
        user.updatetime = time.time()
        user.save(self)
        return self.name

class loginForm(forms.Form):
    name = forms.CharField(max_length=30)
    password = forms.CharField(max_length=32)
    
    def clean_message(self):
        name=self.cleaned_data['name']
        num_words = len(name.split())
        if num_words < 1:
            raise forms.ValidationError("Please enter user name!")
        password = self.cleaned_data['password']
        num_words = len(password.split())
        if num_words < 1:
            raise forms.ValidationError("Please enter password!")
        return forms
